package com.lxm.ymcc.web.controller;

import com.lxm.ymcc.dto.TroDto;
import com.lxm.ymcc.result.JSONResult;
import com.lxm.ymcc.service.ITrollerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.management.Query;
import java.util.List;


@RestController
@RequestMapping("/trolley")
public class TrolleyController {
    @Autowired
   private ITrollerService trollerService;

    @PostMapping("/save")
    public JSONResult save(@RequestBody TroDto troDto){
        trollerService.save(troDto);
        return JSONResult.success();

    }


    @GetMapping("/query/{userId}")
    public JSONResult oneById(@PathVariable("userId") Long userId){
       List<TroDto>  troDtos =  trollerService.oneById(userId);
        return JSONResult.success(troDtos);

    }

    @DeleteMapping("/delete/{userId}/{goodsId}")
    public JSONResult delete(@PathVariable("userId") Long userId,@PathVariable("goodsId") Long goodsId){
        trollerService.delete(userId,goodsId);
        return JSONResult.success();
    }

}
